
########## Perceptions of Social Mobility, Gender, and Progressive Politics ##########
# Authors: Briitta van Staalduinen and Delia Zollinger
# description: Replication code for analyses
# created: November 8, 2024

rm(list = ls())

########### Load packages and data ---------------------------------------------

# packages
if (!require("pacman")) install.packages("pacman") 

pacman::p_load(tidyverse, ggthemes, rio, corrplot, texreg, interactions,lme4,ggpubr, MASS, effects, sjPlot)

theme_set(theme_bw())

load("ERC_replication.Rdata")

########### Preparing data for analysis ----------------------------------------

# gender instead of gender
table(df$age.grp)
table(df$age.grp, df$age)
df$age.grp.2 <- NA
df$age.grp.2[df$age.grp==1|df$age.grp==2] <- "18-35"
df$age.grp.2[df$age.grp==3|df$age.grp==4] <- "36-55"
df$age.grp.2[df$age.grp==5|df$age.grp==6] <- "56+"
table(df$age.grp.2)

# Oesch classes

df$class8_r <- as.factor(df$class8_r)
table(df$class8_r)

df$class <- NA
df$class[df$class8_r==1] <- "EMPL"
df$class[df$class8_r==2] <- "SBO"
df$class[df$class8_r==3] <- "TECH"
df$class[df$class8_r==4] <- "PW"
df$class[df$class8_r==5] <- "MAN"
df$class[df$class8_r==6] <- "CLRK"
df$class[df$class8_r==7] <- "SCP"
df$class[df$class8_r==8] <- "SW"
table(df$class)
df$class <- factor(df$class,levels=c("SCP","EMPL","SBO","TECH","PW","MAN","CLRK","SW"))

df$class <-relevel(df$class, ref = "SCP") # sociocultural professionals as reference category

# Education
table(df$educ, df$educ.grp)
df$educ.grp <- as.factor(df$educ.grp)

# Sector
table(df$lm, df$sector)
df$sector <- as.factor(df$sector)
table(df$sector)

# sector recoded
df$sectrec <- NA
df$sectrec[df$sector==1|df$sector==2|df$sector==3] <- "public"
df$sectrec[df$sector==4] <- "private"
df$sectrec[df$sector==5] <- "selfempl"
table(df$sectrec)

# main household earner
df$mearner <- NA
df$mearner[df$earner==1] <- "resp."
df$mearner[df$earner==2] <- "partner"
df$mearner[df$earner==3] <- "equal"
df$mearner[df$earner==4] <- "other"
df$mearner <- factor(df$mearner, c("resp.", "partner", "equal", "other"))
table(df$mearner)

# part-time
table(df$prttime)
df$parttime[df$prttime==1] <- "no"
df$parttime[df$prttime==2] <- "yes"
table(df$parttime)

# social mobility
df$socmob <- as.factor(df$socmob)
table(df$socmob)

df$socmobc <- NA
df$socmobc[df$socmob==1] <- "lower"
df$socmobc[df$socmob==2] <- "same"
df$socmobc[df$socmob==3] <- "higher"
df$socmobc <- factor(df$socmobc, levels=c("lower", "same", "higher"))
table(df$socmobc)


df$socmob.m <- as.factor(df$socmob.m)
table(df$socmob.m)

df$socmob.mc <- NA
df$socmob.mc[df$socmob.m==1] <- "lower"
df$socmob.mc[df$socmob.m==2] <- "same"
df$socmob.mc[df$socmob.m==3] <- "higher"
df$socmob.mc <- factor(df$socmob.mc, levels=c("lower", "same", "higher"))
table(df$socmob.mc)

# upward mobility
summary(df$socmob)
df$upwm <- NA
df$upwm[df$socmob==1|df$socmob==2] <- 0
df$upwm[df$socmob==3] <- 1
table(df$upwm)
df$upwm <- as.factor(df$upwm)

summary(df$socmob.m)
df$upwm.m <- NA
df$upwm.m[df$socmob.m==1|df$socmob.m==2] <- 0
df$upwm.m[df$socmob.m==3] <- 1
table(df$upwm.m)
df$upwm.m <- as.factor(df$upwm.m)

# long term evolution of society for women
table(df$lngtrmeval.w)
median(df$lngtrmeval.w, na.rm=T)
mean(df$lngtrmeval.w, na.rm=T)

df$gequalpos <- NA
df$gequalpos[df$lngtrmeval.w > 7] <- "positive"
df$gequalpos[df$lngtrmeval.w < 8] <- "negative"
table(df$gequalpos) # dichotomized above the mean

df$gequalposn <- NA
df$gequalposn[df$lngtrmeval.w > 7] <- 1
df$gequalposn[df$lngtrmeval.w < 8] <- 0
table(df$gequalposn) # dichotomized above the mean


# long term evolution of society 
table(df$lngtrmeval)
median(df$lngtrmeval, na.rm=T)
mean(df$lngtrmeval, na.rm=T)

df$socpos <- NA
df$socpos[df$lngtrmeval > 6] <- "positive"
df$socpos[df$lngtrmeval < 7] <- "negative"
table(df$socpos) # dichotomized above the mean

# has kids
table(df$parent)
df$haskids <- NA
df$haskids[df$parent > 0] <- "yes"
df$haskids[df$parent == 0] <- "no"
table(df$haskids)

# Attitudes, sociocultural
table(df$migrnc)
table(df$migrlm)
table(df$euintegr)
table(df$gayadopt)

# feminist ID
table(df$close12)
summary(df$close12)

# childcare position
table(df$pos.cc)

# childcare priority
table(df$imp.cc)

# women and men datasets for later analysis
df_fem <- df %>% filter(gender=="female")
df_male <- df %>% filter(gender=="male")

########## Descriptives --------------------------------------------------------

## Figure 2: Perceived social mobility compared to parents

# left panel: by gender

dfp <- df %>% 
  filter(!is.na(socmobc)) %>% 
  group_by(gender,socmobc) %>% 
  summarise(n=n()) %>% 
  group_by(gender) %>% 
  mutate(perc=100*n/sum(n)) 

dist_socmobc_s <- ggplot(dfp, aes(fill=gender, x=socmobc, y = perc)) +
  geom_bar(position="dodge", stat="identity")+
  xlab("Perceived social mobility") +
  scale_fill_manual(values=c("black", "grey"))
dist_socmobc_s

# right panel: by age and gender

dfp <- df %>% 
  filter(!is.na(socmobc)) %>% 
  group_by(gender,age.grp.2,socmobc) %>% 
  summarise(n=n()) %>% 
  group_by(gender, age.grp.2) %>% 
  mutate(perc=100*n/sum(n))

dist_socmobc_sa <- ggplot(dfp, aes(fill=gender, x=socmobc, y = perc)) +
  geom_bar(position="dodge", stat="identity") +
  xlab("Perceived social mobility ") +
  scale_fill_manual(values=c("black", "grey"))+
  facet_wrap(~ age.grp.2)
dist_socmobc_sa

ggarrange(dist_socmobc_s, dist_socmobc_sa, legend = "bottom", common.legend = T)




########## Figure A1: Perceived social mobility compared to mother

# left panel: by gender

dfp <- df %>% 
  filter(!is.na(socmob.mc)) %>% 
  group_by(gender,socmob.mc) %>% 
  summarise(n=n()) %>% 
  group_by(gender) %>% 
  mutate(perc=100*n/sum(n))

dist_socmob.mc_s <- ggplot(dfp, aes(fill=gender, x=socmob.mc, y = perc)) +
  geom_bar(position="dodge", stat="identity") +
  xlab("Perceived social mobility") +
  scale_fill_manual(values=c("black", "grey"))
dist_socmob.mc_s

# right panel: by age and gender

dfp <- df %>% 
  filter(!is.na(socmob.mc)) %>% 
  group_by(gender,age.grp.2, socmob.mc) %>% 
  summarise(n=n()) %>% 
  group_by(gender, age.grp.2) %>% 
  mutate(perc=100*n/sum(n))

dist_socmob.mc_sa <- ggplot(dfp, aes(fill=gender, x=socmob.mc, y = perc)) +
  geom_bar(position="dodge", stat="identity") +
  xlab("Perceived social mobility")  +
  scale_fill_manual(values=c("black", "grey"))+
  facet_wrap(~ age.grp.2)
dist_socmob.mc_sa

ggarrange(dist_socmob.mc_s, dist_socmob.mc_sa,legend = "bottom", common.legend = T)




########## Figure B1: by country

dfp <- df %>% 
  filter(!is.na(socmobc)) %>% 
  group_by(gender,country,socmobc) %>% 
  summarise(n=n()) %>% 
  group_by(gender, country) %>% 
  mutate(perc=100*n/sum(n)) 

dist_socmobc_cntry <- ggplot(dfp, aes(fill=gender, x=socmobc, y = perc)) +
  geom_bar(position="dodge", stat="identity") +
  xlab("Perceived social mobility ") +
  scale_fill_manual(values=c("black", "grey"))+
  facet_wrap(~ country)
dist_socmobc_cntry




########## Figure 3: Long-term evaluation of social change for women

# left panel: by gender

dist_lngtrmeval.w_s <- ggplot(df, aes(lngtrmeval.w, color=gender)) +
  geom_density(position="identity", adjust=1.5) +
  xlab("Long term evaluation of social change for women (1 = worse, 10 = better)") +
  scale_color_manual(values=c("black", "darkgrey"))
dist_lngtrmeval.w_s

# right panel: by age and gender

dist_lngtrmeval.w_sa <- ggplot(df, aes(lngtrmeval.w, color=gender)) +
  geom_density(position="identity", adjust=1.5) +
  xlab("Long term evaluation of social change for women (1 = worse, 10 = better)") +
  facet_wrap(~ age.grp.2)+
  scale_color_manual(values=c("black", "darkgrey"))
dist_lngtrmeval.w_sa

ggarrange(dist_lngtrmeval.w_s, dist_lngtrmeval.w_sa,legend = "bottom", common.legend = T)





########## Figure B.2: by country

dist_lngtrmeval_cntry <- ggplot(df, aes(lngtrmeval.w, color=gender)) +
  geom_density(position="identity", adjust=1.5) +
  xlab("Long term evaluation of social change for women (1 = worse, 10 = better)") +
  facet_wrap(~ country)+
  scale_color_manual(values=c("black", "darkgrey"))
dist_lngtrmeval_cntry




########## Figure B.3: general social change by country

dist_lngtrmeval_cntry <- ggplot(df, aes(lngtrmeval, color=gender)) +
  geom_density(position="identity", adjust=1.5) +
  xlab("Long term evaluation of social change (1 = worse, 10 = better)") +
  facet_wrap(~ country)+
  scale_color_manual(values=c("black", "darkgrey"))
dist_lngtrmeval_cntry




#################### Analysis --------------------------------------------------

########## Figure 4: Individual mobility perceptions x gender on opportunity perceptions

# left panel: comparison to parents 

m1b.op.sm <- lm(oppecon ~ gender*socmobc + educ.grp + age + factor(country), df)
screenreg(m1b.op.sm)

inter_opp_socmob <- cat_plot(m1b.op.sm, 
                             pred = socmobc, 
                             modx = gender, 
                             geom = "line", 
                             data = df,
                             errorbar.width = 0.2,
                             dodge.width = 0.2,
                             x.label = "social mobility compared to parents",
                             y.label = "opportunity perceptions (negative - positive)",
                             colors = c("black", "darkgrey")) +
  theme_bw() +
  theme(legend.position = "none")  

inter_opp_socmob <- inter_opp_socmob +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                   
            hjust = 1.2,                    
            size = 4) 
inter_opp_socmob

# right panel: comparison to mother

m2b.op.sm <- lm(oppecon ~ gender*socmob.mc + educ.grp + age + factor(country), df)
screenreg(m2b.op.sm)

inter_opp_socmob.m <-  cat_plot(m2b.op.sm, 
                                 pred = socmob.mc, 
                                 modx = gender, 
                                 geom = "line", 
                                 data = df,
                                 errorbar.width = 0.2,
                                 dodge.width = 0.2,
                                 x.label = "social mobility compared to mother",
                                 y.label = "opportunity perceptions (negative - positive)",
                                 colors = c("black", "darkgrey")) +
  theme_bw() +
  theme(legend.position = "none")  
inter_opp_socmob.m

inter_opp_socmob.m <- inter_opp_socmob.m +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,                  
            hjust = 1.2,                   
            size = 4) 
inter_opp_socmob.m

inter_opp_mobility <- ggarrange(inter_opp_socmob, inter_opp_socmob.m, common.legend = T, legend = "none")
inter_opp_mobility




########## Figure 5: Long-term social change x gender on opportunity perceptions

# left panel: change for women

m1b.op.lngtrmeval.w <- lm(oppecon ~ gender*lngtrmeval.w + educ.grp + age + factor(country), df)
screenreg(m1b.op.lngtrmeval.w)

# with social mobility as covariate
m1c.op.lngtrmeval.w <- lm(oppecon ~ gender*lngtrmeval.w + socmobc + educ.grp + age + factor(country), df)
screenreg(m1c.op.lngtrmeval.w)

# with social mobility compared to mother as covariate
m1d.op.lngtrmeval.w <- lm(oppecon ~ gender*lngtrmeval.w + socmob.mc + educ.grp + age + factor(country), df)
screenreg(m1d.op.lngtrmeval.w)


inter_opp_lngtrmeval.w <- interact_plot(m1b.op.lngtrmeval.w, lngtrmeval.w, modx = gender, data = df,
                                        errorbar.width = 0.2,
                                        dodge.width = 0.2,
                                        x.label = "long-term evaluation of social change for women",
                                        y.label = "opportunity perceptions (negative - positive)",
                                        colors=c("black", "darkgrey"),
                                        legend.main = "gender",
                                        interval = T)  +
  theme_bw()+
  theme(legend.position = "none")
inter_opp_lngtrmeval.w 

inter_opp_lngtrmeval.w <- inter_opp_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 4.85, label = "m"),  
            size = 5,                      
            color = "darkgrey")             

inter_opp_lngtrmeval.w <- inter_opp_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 4, label = "w"), 
            size = 5,                     
            color = "black") 
inter_opp_lngtrmeval.w

# right panel: general change

m2b.op.lngtrmeval <- lm(oppecon ~ gender*lngtrmeval + educ.grp + age + factor(country), df)
screenreg(m2b.op.lngtrmeval)

inter_opp_lngtrmeval <- interact_plot(m2b.op.lngtrmeval, lngtrmeval, modx = gender, data = df,
                                        errorbar.width = 0.2,
                                        dodge.width = 0.2,
                                        x.label = "long-term evaluation of social change (general)",
                                        y.label = "opportunity perceptions (negative - positive)",
                                        colors=c("black", "darkgrey"),
                                        legend.main = "gender",
                                        interval = T)  +
  theme_bw()+
  theme(legend.position = "none")
inter_opp_lngtrmeval

inter_opp_lngtrmeval <- inter_opp_lngtrmeval +
  geom_text(aes(x = 2.5, y = 4.85, label = "m"),  
            size = 5,                     
            color = "darkgrey")               

inter_opp_lngtrmeval <- inter_opp_lngtrmeval +
  geom_text(aes(x = 2.5, y = 4, label = "w"), 
            size = 5,                      
            color = "black") 
inter_opp_lngtrmeval

inter_opp_evaluations<- ggarrange(inter_opp_lngtrmeval.w, inter_opp_lngtrmeval, common.legend = T, legend = "none")




########## Table D1: Regression table for figures 4 and 5 

texreg(list(m1b.op.sm,m2b.op.sm,m1b.op.lngtrmeval.w, m2b.op.lngtrmeval, m1c.op.lngtrmeval.w,m1d.op.lngtrmeval.w),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept", "male", "mobility=parents", "mobility>parents","medium education", "high education", "age",
                             "Spain", "Sweden", "UK","male*mobility=parents", "male*mobility>parents", "mobility=mother", "mobility>mother",
                             "male*mobility=mother", "male*mobility>mother","eval change women", "male*eval change women", "eval social change",
                             "male*eval social change"))




########## Figure 6: individual mobility perceptions x gender on general socio-cultural attitudes

# left panel: migration
m.1.migrlm <- lm(migrlm ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.migrlm)

inter_migrlm_socmobc <-  cat_plot(m.1.migrlm, 
                                pred = socmobc, 
                                modx = gender, 
                                geom = "line", 
                                data = df,
                                errorbar.width = 0.2,
                                dodge.width = 0.2,
                                x.label = "Social mobility (compared to parents)",
                                y.label = "1 = pro-immigration - 4 = anti-immigration",
                                colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2,3) +
  theme(legend.position = "none")  # Remove the legend
inter_migrlm_socmobc

inter_migrlm_socmobc <- inter_migrlm_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,                 
            hjust = 1.2,                    
            size = 4) 
inter_migrlm_socmobc

# middle panel: gay rights

m.1.gayadopt <- lm(gayadopt ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.gayadopt)

inter_gayadopt_socmobc <-  cat_plot(m.1.gayadopt, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "1 = anti-gay adoption - 4 = pro-gay adoption",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2.5,3.5) +
  theme(legend.position = "none") 
inter_gayadopt_socmobc

inter_gayadopt_socmobc <- inter_gayadopt_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                  
            hjust = 1.2,                   
            size = 4) 
inter_gayadopt_socmobc

# right panel: eu integration

m.1.euintegr <- lm(euintegr ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.euintegr)

inter_euintegr_socmobc <-  cat_plot(m.1.euintegr, 
                                    pred = socmobc, 
                                    modx = gender, 
                                    geom = "line", 
                                    data = df,
                                    errorbar.width = 0.2,
                                    dodge.width = 0.2,
                                    x.label = "Social mobility (compared to parents)",
                                    y.label = "1 = pro-EU - 4 = anti-EU",
                                    colors = c("black", "darkgrey")) +
  theme_bw() +  
  ylim(2.25,3.25) +
  theme(legend.position = "none")
inter_euintegr_socmobc

inter_euintegr_socmobc <- inter_euintegr_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                 
            hjust = 1.2,                   
            size = 4) 
inter_euintegr_socmobc

inter_att_socmob<- ggarrange(inter_migrlm_socmobc, inter_euintegr_socmobc, inter_gayadopt_socmobc,nrow=1, common.legend = T, legend = "none")




########## Table D2: socio-cultural attitudes and individual trajectory

texreg(list(m.1.migrlm,m.1.gayadopt,m.1.euintegr),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept","Spain","Sweden","UK",
                             "medium education", "high education", "age","male",
                             "mobility=parents", "mobility>parents","male*mobility=parents","male*mobility>parents"))




########## Figure D2: collective mobility evaluations x gender on general socio-cultural attitudes

# left panel: migration

m.1.migrlm <- lm(migrlm ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.migrlm)

inter_migrlm_lngtrmeval.w <- interact_plot(m.1.migrlm, lngtrmeval.w, modx = gender, data = df,
                                      x.label = "long-term evaluation of social change for women",
                                      y.label = "1 = pro-immigration - 4 = anti-immigration",
                                      colors=c("black", "darkgrey"),
                                      legend.main = "gender",
                                      interval = T)  +
  theme_bw()+
  ylim(2,3) +
  theme(legend.position = "none")
inter_migrlm_lngtrmeval.w

inter_migrlm_lngtrmeval.w <- inter_migrlm_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 2.78, label = "m"),  
            size = 5,                   
            color = "darkgrey")           

inter_migrlm_lngtrmeval.w <- inter_migrlm_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 2.6, label = "w"),
            size = 5,                    
            color = "black") 
inter_migrlm_lngtrmeval.w

# middle panel: gay rights

m.1.gayadopt <- lm(gayadopt ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.gayadopt)

inter_gayadopt_lngtrmeval.w <- interact_plot(m.1.gayadopt, lngtrmeval.w, modx = gender, data = df,
                                           x.label = "long-term evaluation of social change for women",
                                           y.label = "1 = anti-gay adoption - 4 = pro-gay adoption",
                                           colors=c("black", "darkgrey"),
                                           legend.main = "gender",
                                           interval = T)  +
  theme_bw()+
  ylim(2.5,3.5) +
  theme(legend.position = "none")
inter_gayadopt_lngtrmeval.w

inter_gayadopt_lngtrmeval.w <- inter_gayadopt_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 2.8, label = "m"),  
            size = 5,                    
            color = "darkgrey")            

inter_gayadopt_lngtrmeval.w <- inter_gayadopt_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 3.17, label = "w"), 
            size = 5,                   
            color = "black") 
inter_gayadopt_lngtrmeval.w

# right panel: eu integration

m.1.euintegr <- lm(euintegr ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.euintegr)

inter_euintegr_lngtrmeval.w <- interact_plot(m.1.euintegr, lngtrmeval.w, modx = gender, data = df,
                                             x.label = "long-term evaluation of social change for women",
                                             y.label = "1 = pro-EU - 4 = anti-EU",
                                             colors=c("black", "darkgrey"),
                                             legend.main = "gender",
                                             interval = T)  +
  theme_bw()+
  ylim(2.4,3.4) +
  theme(legend.position = "none")
inter_euintegr_lngtrmeval.w 

inter_euintegr_lngtrmeval.w <- inter_euintegr_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 3.02, label = "m"), 
            size = 5,                   
            color = "darkgrey")              

inter_euintegr_lngtrmeval.w <- inter_euintegr_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 2.84, label = "w"), 
            size = 5,                    
            color = "black") 
inter_euintegr_lngtrmeval.w

inter_att_lngtrmeval.w<- ggarrange(inter_migrlm_lngtrmeval.w, inter_euintegr_lngtrmeval.w, inter_gayadopt_lngtrmeval.w,nrow=1, common.legend = T, legend = "bottom")

## Table D5: socio-cultural attitudes and collective trajectory

texreg(list(m.1.migrlm,m.1.euintegr,m.1.gayadopt),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept","Spain","Sweden","UK",
                             "medium education", "high education", "age","male",
                             "eval change women","male*eval change women"))




########## Figure D1: individual mobility perceptions x gender on gender-related attitudes

# left panel: feminist identity
m.1.close12 <- lm(close12 ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.close12)

inter_fem_socmobc <-  cat_plot(m.1.close12, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "Feminist identity (1=not at all close, 10=very close)",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(3,5) +
  theme(legend.position = "none") 
inter_fem_socmobc

inter_fem_socmobc <- inter_fem_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,                  
            hjust = 1.2,                  
            size = 4) 
inter_fem_socmobc

# middle panel: expansion of childcare

m.1.pos.cc <- lm(pos.cc ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.pos.cc)

inter_pos.cc_socmobc <-  cat_plot(m.1.pos.cc, 
                               pred = socmobc, 
                               modx = gender, 
                               geom = "line", 
                               data = df,
                               errorbar.width = 0.2,
                               dodge.width = 0.2,
                               x.label = "Social mobility (compared to parents)",
                               y.label = "Childcare services (1=reduce, 7=expand)",
                               colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(4.75,5.75) +
  theme(legend.position = "none") 
inter_pos.cc_socmobc

inter_pos.cc_socmobc <- inter_pos.cc_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                  
            hjust = 1.2,               
            size = 4) 
inter_pos.cc_socmobc

# left panel: importance of expanding childcare

m.1.imp.cc <- lm(imp.cc ~ factor(country) + educ.grp  + age + gender*socmobc, df)
screenreg(m.1.imp.cc)

inter_imp.cc_socmobc <-  cat_plot(m.1.imp.cc, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "Expanding childcare (1=not at all urgent, 4=very urgent)",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2.75,3.25) +
  theme(legend.position = "none") 
inter_imp.cc_socmobc

inter_imp.cc_socmobc<- inter_imp.cc_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                  
            hjust = 1.2,                   
            size = 4) 
inter_imp.cc_socmobc

inter_gatt_socmobc<- ggarrange(inter_fem_socmobc, inter_pos.cc_socmobc, inter_imp.cc_socmobc,nrow=1, common.legend = T, legend = "none")

## Table D4: gender attitudes and individual trajectory
texreg(list(m.1.close12,m.1.pos.cc,m.1.imp.cc),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept","Spain","Sweden","UK",
                             "medium education", "high education", "age","male",
                             "mobility=parents", "mobility>parents",
                             "male*mobility=parents", "male*mobility>parents"))




########## Figure 7: collective mobility evaluations x gender on gender-related attitudes

# left panel: feminist identity

m.1.close12 <- lm(close12 ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.close12)

inter_fem_lngtrmeval.w <- interact_plot(m.1.close12, lngtrmeval.w, modx = gender, data = df,
                                             x.label = "long-term evaluation of social change for women",
                                             y.label = "Feminist identity (1=not at all close, 10=very close)",
                                             colors=c("black", "darkgrey"),
                                             legend.main = "gender",
                                             interval = T)  +
  theme_bw()+
  ylim(3,5) +
  theme(legend.position = "none")
inter_fem_lngtrmeval.w

inter_fem_lngtrmeval.w <- inter_fem_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 3.7, label = "m"),
            size = 5,                    
            color = "darkgrey")              

inter_fem_lngtrmeval.w <- inter_fem_lngtrmeval.w +
  geom_text(aes(x = 2.5, y = 4.5, label = "w"), 
            size = 5,                      
            color = "black") 
inter_fem_lngtrmeval.w

# middle panel: expansion of childcare

m.1.pos.cc <- lm(pos.cc ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.pos.cc)

inter_pos.cc_lngtrmeval.w <- interact_plot(m.1.pos.cc, lngtrmeval.w, modx = gender, data = df,
                                        x.label = "long-term evaluation of social change for women",
                                        y.label = "Childcare services (1=reduce, 7=expand)",
                                        colors=c("black", "darkgrey"),
                                        legend.main = "gender",
                                        interval = T)  +
  theme_bw()+
  ylim(4.75,5.75) +
  theme(legend.position = "none")
inter_pos.cc_lngtrmeval.w

inter_pos.cc_lngtrmeval.w <- inter_pos.cc_lngtrmeval.w+
  geom_text(aes(x = 7.5, y = 5.12, label = "m"), 
            size = 5,                      
            color = "darkgrey")              

inter_pos.cc_lngtrmeval.w<- inter_pos.cc_lngtrmeval.w+
  geom_text(aes(x = 7.5, y = 5.39, label = "w"),
            size = 5,                     
            color = "black") 
inter_pos.cc_lngtrmeval.w

# right panel: importance of expanding childcare

m.1.imp.cc <- lm(imp.cc ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, df)
screenreg(m.1.imp.cc)

inter_imp.cc_lngtrmeval.w <- interact_plot(m.1.imp.cc, lngtrmeval.w, modx = gender, data = df,
                                           x.label = "long-term evaluation of social change for women",
                                           y.label = "Expanding childcare (1=not at all urgent, 4=very urgent)",
                                           colors=c("black", "darkgrey"),
                                           legend.main = "gender",
                                           interval = T)  +
  theme_bw()+
  ylim(2.75,3.25) +
  theme(legend.position = "none")
inter_imp.cc_lngtrmeval.w

inter_imp.cc_lngtrmeval.w <- inter_imp.cc_lngtrmeval.w+
  geom_text(aes(x = 7.5, y = 2.95, label = "m"), 
            size = 5,                     
            color = "darkgrey")             

inter_imp.cc_lngtrmeval.w<- inter_imp.cc_lngtrmeval.w+
  geom_text(aes(x = 7.5, y = 3.11, label = "w"),
            size = 5,                     
            color = "black") 
inter_imp.cc_lngtrmeval.w

inter_gatt_lngtrmeval.w<- ggarrange(inter_fem_lngtrmeval.w, inter_pos.cc_lngtrmeval.w, inter_imp.cc_lngtrmeval.w,nrow=1, common.legend = T, legend = "none")

## Table D6: : gender attitudes and collective trajectory, controlling for individual trajectory

m.2.close12 <- lm(close12 ~ factor(country) + educ.grp  + age + socmobc + gender*lngtrmeval.w, df)
m.2.pos.cc <- lm(pos.cc ~ factor(country) + educ.grp  + age + socmobc + gender*lngtrmeval.w, df)
m.2.imp.cc <- lm(imp.cc ~ factor(country) + educ.grp  + age + socmobc + gender*lngtrmeval.w, df)

texreg(list(m.2.close12,m.2.pos.cc,m.2.imp.cc),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept","Spain","Sweden","UK",
                             "medium education", "high education", "age",
                             "mobility=parents", "mobility>parents", "male",
                             "eval change women","male*eval change women"))

## Table D7: interaction between collective evaluations x individual mobility on outcomes among women only

m.int.opp <- lm(oppecon ~ factor(country) + educ.grp + age + lngtrmeval.w*socmobc, df_fem)
m.int.femid <- lm(close12 ~ factor(country) + educ.grp + age + lngtrmeval.w*socmobc, df_fem)
m.int.pos.cc <- lm(pos.cc ~ factor(country) + educ.grp + age + lngtrmeval.w*socmobc, df_fem)
m.int.imp.cc <- lm(imp.cc ~ factor(country) + educ.grp + age + lngtrmeval.w*socmobc, df_fem)

screenreg(list(m.int.opp,m.int.femid,m.int.pos.cc,m.int.imp.cc))

texreg(list(m.int.opp,m.int.femid,m.int.pos.cc,m.int.imp.cc),
       stars = c(0.001, 0.01, 0.05),
       custom.coef.names = c("Intercept","Spain","Sweden","UK",
                             "medium education", "high education", "age","eval change women",
                             "mobility=parents", "mobility>parents",
                             "eval change women*mobility=parents","eval change women*mobility>parents"))




########## Appendix C 

# predictors of individual mobility perceptions, by gender 

df$country <- as.factor(df$country)

m.0.pred.socmob <- polr(socmobc ~ educ.grp*gender+age+country, df, Hess=TRUE)
screenreg(m.0.pred.socmob)

plot(Effect(focal.predictors = c("gender","educ.grp"), m.0.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.1.pred.socmob <- polr(socmobc ~ class*gender+age+country, df, Hess=TRUE)
screenreg(m.1.pred.socmob)

plot(Effect(focal.predictors = c("gender","class"), m.1.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.2.pred.socmob <- polr(socmobc ~ sectrec*gender+age+country, df, Hess=TRUE)
screenreg(m.2.pred.socmob)

plot(Effect(focal.predictors = c("gender","sectrec"), m.2.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.3.pred.socmob <- polr(socmobc ~ mearner*gender+age+country, df, Hess=TRUE) # interaction
screenreg(m.3.pred.socmob)

plot(Effect(focal.predictors = c("gender","mearner"), m.3.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.4.pred.socmob <- polr(socmobc ~ haskids*gender+age+country, df, Hess=TRUE)
screenreg(m.4.pred.socmob)  

plot(Effect(focal.predictors = c("gender","haskids"), m.4.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.5.pred.socmob <- polr(socmobc ~ age.grp.2*gender+country, df, Hess=TRUE)
screenreg(m.5.pred.socmob)

plot(Effect(focal.predictors = c("gender","age.grp.2"), m.5.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.6.pred.socmob <- polr(socmobc ~ income*gender+age+country, df, Hess=TRUE)
screenreg(m.6.pred.socmob)

plot(Effect(focal.predictors = c("gender","income"), m.6.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

m.7.pred.socmob <- polr(socmobc ~ parttime*gender+age+country, df, Hess=TRUE)
screenreg(m.7.pred.socmob)

plot(Effect(focal.predictors = c("parttime","gender"), m.7.pred.socmob), rug = FALSE, main="", ylab="Pr(social mobility)", colors="black")
dev.off()

# predictors of collective mobility perceptions, by gender 

m.0.pred.col <- lm(lngtrmeval.w ~ educ.grp*gender+age+country, df)
screenreg(m.0.pred.col)

plot_model(m.0.pred.col, type = "pred", terms = c("educ.grp", "gender"))+
  labs(title="")+
  xlab("education (1=low, 2=med, 3=high)")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.1.pred.col <- lm(lngtrmeval.w ~ class*gender+age+country, df) 
screenreg(m.1.pred.col)

plot_model(m.1.pred.col, type = "pred", terms = c("class", "gender"))+
  labs(title="")+
  xlab("class")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.2.pred.col <- lm(lngtrmeval.w ~ sectrec*gender+age+country, df)
screenreg(m.2.pred.col)

plot_model(m.2.pred.col, type = "pred", terms = c("sectrec", "gender"))+
  labs(title="")+
  xlab("sector")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.3.pred.col <- lm(lngtrmeval.w ~ mearner*gender+age+country, df) 
screenreg(m.3.pred.col)

plot_model(m.3.pred.col, type = "pred", terms = c("mearner", "gender"))+
  labs(title="")+
  xlab("main household earner")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.4.pred.col <- lm(lngtrmeval.w ~ haskids*gender+age+country, df)
screenreg(m.4.pred.col)

plot_model(m.4.pred.col, type = "pred", terms = c("haskids", "gender"))+
  labs(title="")+
  xlab("has kids")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

df$age.grp.2 <- factor(df$age.grp.2, levels=c("18-35", "36-55", "56+"))
m.5.pred.col <- lm(lngtrmeval.w ~ age.grp.2*gender+country, df)
screenreg(m.5.pred.col)

plot_model(m.5.pred.col, type = "pred", terms = c("age.grp.2", "gender"))+
  labs(title="")+
  xlab("age group")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.6.pred.col <- lm(lngtrmeval.w ~ income*gender+age+country, df)
screenreg(m.6.pred.col)

plot_model(m.6.pred.col, type = "pred", terms = c("income", "gender"))+
  labs(title="")+
  xlab("income (deciles)")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

m.7.pred.col <- lm(lngtrmeval.w ~ parttime*gender+age+country, df)
screenreg(m.7.pred.col)

plot_model(m.7.pred.col, type = "pred", terms = c("parttime", "gender"))+
  labs(title="")+
  xlab("part time employment")+
  ylab("perception of women's collective gains")+
  scale_color_manual(name="gender",values=c("black", "grey")) +
  theme_sjplot2()

screenreg(list(m.0.pred.col, m.1.pred.col, m.2.pred.col))
screenreg(list(m.3.pred.col, m.4.pred.col, m.5.pred.col))
screenreg(list(m.6.pred.col, m.7.pred.col))




########## Robustness check, sample limited to upwardly mobile

dfum <- df %>% filter(socmobc!="lower")

m.1.opp <- lm(oppecon ~ factor(country) + educ.grp + age + gender*lngtrmeval.w, dfum)
m.1.close12 <- lm(close12 ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, dfum)
m.1.pos.cc <- lm(pos.cc ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, dfum)
m.1.imp.cc <- lm(imp.cc ~ factor(country) + educ.grp  + age + gender*lngtrmeval.w, dfum)

screenreg(list(m.1.opp,m.1.close12,m.1.pos.cc, m.1.imp.cc)) 




########## Figure E1 and E2: Robustness check, meritocracy beliefs 

# recode lmsuc1 variable, meritocracy (hard work)
df$merit_work <- NA
df$merit_work[df$lmsuc1==3] <- 1
df$merit_work[df$lmsuc1==1|df$lmsuc1==2|df$lmsuc1==4] <- 0
table(df$merit_work)

m.1.merit.hw <- lm(gayadopt ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.1.merit.hw)

m.2.merit.hw <- lm(euintegr ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.2.merit.hw)

m.3.merit.hw <- lm(migrlm ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.3.merit.hw)

# general socio-cultural progressivism with control for meritocratic beliefs
# left panel: migration
inter_meritim_socmobc <- cat_plot(m.3.merit.hw, 
                             pred = socmobc, 
                             modx = gender, 
                             geom = "line", 
                             data = df,
                             errorbar.width = 0.2,
                             dodge.width = 0.2,
                             x.label = "Social mobility (compared to parents)",
                             y.label = "1 = pro-immigration - 4 = anti-immigration",
                             colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2,3) +
  theme(legend.position = "none") 

inter_meritim_socmobc <- inter_meritim_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                  
            hjust = 1.2,                 
            size = 4) 
inter_meritim_socmobc

# middle panel: gay rights
inter_meritga_socmobc <- cat_plot(m.1.merit.hw, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "1 = anti-gay adoption - 4 = pro-gay adoption",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2.5,3.5) +
  theme(legend.position = "none")  

inter_meritga_socmobc <- inter_meritga_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                  
            hjust = 1.2,                  
            size = 4) 
inter_meritga_socmobc

# right panel: eu integration
inter_meriteu_socmobc <- cat_plot(m.2.merit.hw, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "1 = anti-gay adoption - 4 = pro-gay adoption",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2.25,3.25) +
  theme(legend.position = "none")  

inter_meriteu_socmobc <- inter_meriteu_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,                  
            hjust = 1.2,                
            size = 4) 
inter_meriteu_socmobc

inter_meritatt_socmob<- ggarrange(inter_meritim_socmobc, inter_meriteu_socmobc,inter_meritga_socmobc,nrow=1, common.legend = T, legend = "none")
inter_meritatt_socmob

## socio-cultural progressivism specific to gender equality with controls for meritocratic beliefs

m.4.merit.hw <- lm(pos.cc ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.4.merit.hw)

m.5.merit.hw <- lm(imp.cc ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.5.merit.hw)

m.6.merit.hw <- lm(close12 ~ factor(country) + educ.grp  + age + gender*socmobc + merit_work, df)
summary(m.6.merit.hw)

# left panel: feminist identity
inter_meritf_socmobc <- cat_plot(m.6.merit.hw, 
                                  pred = socmobc, 
                                  modx = gender, 
                                  geom = "line", 
                                  data = df,
                                  errorbar.width = 0.2,
                                  dodge.width = 0.2,
                                  x.label = "Social mobility (compared to parents)",
                                  y.label = "Feminist identity (1=not at all close, 10=very close)",
                                  colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(3,5) +
  theme(legend.position = "none")  

inter_meritf_socmobc <- inter_meritf_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2),  
            vjust = -0.5,                 
            hjust = 1.2,                  
            size = 4) 
inter_meritf_socmobc

# middle panel: expansion of childcare
inter_meritpos_socmobc <- cat_plot(m.4.merit.hw, 
                                 pred = socmobc, 
                                 modx = gender, 
                                 geom = "line", 
                                 data = df,
                                 errorbar.width = 0.2,
                                 dodge.width = 0.2,
                                 x.label = "Social mobility (compared to parents)",
                                 y.label = "Childcare services (1=reduce, 7=expand)",
                                 colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(4.75,5.75) +
  theme(legend.position = "none") 

inter_meritpos_socmobc <- inter_meritpos_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,                  
            hjust = 1.2,                 
            size = 4) 
inter_meritpos_socmobc

# left panel: importance of expanding childcare
inter_meritimp_socmobc <- cat_plot(m.5.merit.hw, 
                                   pred = socmobc, 
                                   modx = gender, 
                                   geom = "line", 
                                   data = df,
                                   errorbar.width = 0.2,
                                   dodge.width = 0.2,
                                   x.label = "Social mobility (compared to parents)",
                                   y.label = "Expanding childcare (1=not at all urgent, 4=very urgent)",
                                   colors = c("black", "darkgrey")) +
  theme_bw() +
  ylim(2.75,3.25) +
  theme(legend.position = "none") 

inter_meritimp_socmobc <- inter_meritimp_socmobc +
  geom_text(aes(label = ifelse(gender == "male", "m", "w")), 
            position = position_dodge(0.2), 
            vjust = -0.5,              
            hjust = 1.2,              
            size = 4) 
inter_meritimp_socmobc

inter_meritgatt_socmobc<- ggarrange(inter_meritf_socmobc, inter_meritpos_socmobc, inter_meritimp_socmobc,nrow=1, common.legend = T, legend = "none")
inter_meritgatt_socmobc

